using System;
using System.Collections;
using System.Collections.Generic;

namespace etcetera.Mvc.UI.Toolbar
{
    public class ColumnModelBuilder : ICollection<ColumnModel>
    {
        private readonly List<ColumnModel> _columns = new List<ColumnModel>();
        
        #region Implementation of IEnumerable

        public ColumnModel For(string keyName)
        {
            var column = new ColumnModel { Key = keyName };
            _columns.Add(column);

            return column;
        }

        public ColumnModel For(string keyName, string link)
        {
            var column = new ColumnModel { Key = keyName, Link = link };
            _columns.Add(column);

            return column;
        }

        public ColumnModel For(string keyName, string linkFormat, string linkKey)
        {
            var column = new ColumnModel { Key = keyName, Link = linkFormat, LinkKey = linkKey };
            _columns.Add(column);

            return column;
        }

        public IEnumerator<ColumnModel> GetEnumerator()
        {
            return _columns.GetEnumerator();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }

        #endregion

        #region Implementation of ICollection<ColumnModel>

        public void Add(ColumnModel columnModel)
        {
            _columns.Add(columnModel);
        }

        public void Clear()
        {
            _columns.Clear();
        }

        public bool Contains(ColumnModel columnModel)
        {
            return _columns.Contains(columnModel);
        }

        public void CopyTo(ColumnModel[] array, int arrayIndex)
        {
            _columns.CopyTo(array, arrayIndex);
        }

        public bool Remove(ColumnModel columnModel)
        {
            return _columns.Remove(columnModel);
        }

        public int Count
        {
            get { return _columns.Count; }
        }

        public bool IsReadOnly
        {
            get { return false; }
        }

        #endregion
    }
}